package com.minsus.secretmailbox;

import org.apache.cordova.api.PluginResult.Status;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.telephony.TelephonyManager;

import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;

public class GetMyNumber extends Plugin
{
    @Override
    public PluginResult execute(String action, JSONArray args, String callbackId)
    {
        TelephonyManager telephony = (TelephonyManager)this.ctx.getSystemService(Context.TELEPHONY_SERVICE);
        String myNumber =  telephony.getLine1Number();

        JSONObject jo = new JSONObject();

        try
        {
            jo.put("number", myNumber);
        }
        catch (JSONException e)
        {
            e.printStackTrace();
        }

        return new PluginResult(Status.OK, jo);
    }
}
